import Taro, { Component } from '@tarojs/taro'
import { Image, Text, View } from '@tarojs/components'
import classNames from 'classnames'
import { toMemberOpenPage } from "@/utils/page_router"
import vipImg from "@/assets/icon/vip.png"
import styles from './index.module.scss'
// import './index.scss'

interface IProps {
  className: string
  goods: any
  user: any
}

/**
 * 商品优惠
 */
export default class GoodsDiscount extends Component<IProps, {}> {
  props: any

  render() {
    const prefixCls = 'discount'
    const { goods, user, className } = this.props
    return goods.memberPrice > 0 && goods.salePrice !== goods.memberPrice && (
      <View className={classNames(styles[prefixCls], className)} onClick={() => toMemberOpenPage()}>
        <View className={styles[`${prefixCls}-left`]}>
          <Image src={vipImg} className={styles[`${prefixCls}-left-icon`]}/>
          <View className={styles[`${prefixCls}-left-text`]}>
            会员价<Text className={styles[`${prefixCls}-price`]}>￥{goods.memberPrice}</Text>{goods.saveMoney ? `省￥${goods.saveMoney}` : ''}
          </View>
        </View>
        <View className={styles[`${prefixCls}-right`]}>
          <View className={styles[`${prefixCls}-right-text`]}>{user.isVip ? '' : '立即开通'}</View>
          <View className={classNames(styles[`${prefixCls}-right-icon`], 'bnn-icon')}>&#xe866;</View>
        </View>
      </View>
    )
  }
}
